package edu.zut.hb.ambition.outpatienttype.spring.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import common.annotation.Log;
import common.core.controller.BaseController;
import common.core.domain.AjaxResult;
import common.enums.BusinessType;
import common.utils.poi.ExcelUtil;
import common.core.page.TableDataInfo;


@RestController
@RequestMapping("/system/outpatienttype")
public class OutpatienttypeController extends BaseController
{
    @Autowired
    private IOutpatienttypeService outpatienttypeService;

    @PreAuthorize("@ss.hasPermi('system:outpatienttype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Outpatienttype outpatienttype)
    {
        startPage();
        List<Outpatienttype> list = outpatienttypeService.selectOutpatienttypeList(outpatienttype);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:outpatienttype:export')")
    @Log(title = "门诊收费项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Outpatienttype outpatienttype)
    {
        List<Outpatienttype> list = outpatienttypeService.selectOutpatienttypeList(outpatienttype);
        ExcelUtil<Outpatienttype> util = new ExcelUtil<Outpatienttype>(Outpatienttype.class);
        util.exportExcel(response, list, "门诊收费项目数据");
    }


    @PreAuthorize("@ss.hasPermi('system:outpatienttype:query')")
    @GetMapping(value = "/{outpatientid}")
    public AjaxResult getInfo(@PathVariable("outpatientid") Long outpatientid)
    {
        return AjaxResult.success(outpatienttypeService.selectOutpatienttypeByOutpatientid(outpatientid));
    }


    @PreAuthorize("@ss.hasPermi('system:outpatienttype:add')")
    @Log(title = "门诊收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Outpatienttype outpatienttype)
    {
        return toAjax(outpatienttypeService.insertOutpatienttype(outpatienttype));
    }


    @PreAuthorize("@ss.hasPermi('system:outpatienttype:edit')")
    @Log(title = "门诊收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Outpatienttype outpatienttype)
    {
        return toAjax(outpatienttypeService.updateOutpatienttype(outpatienttype));
    }


    @PreAuthorize("@ss.hasPermi('system:outpatienttype:remove')")
    @Log(title = "门诊收费项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outpatientids}")
    public AjaxResult remove(@PathVariable Long[] outpatientids)
    {
        return toAjax(outpatienttypeService.deleteOutpatienttypeByOutpatientids(outpatientids));
    }
}
